package cn.senjoeson.triper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.senjoeson.mylibrary.utilschanged.GlideUtils;
import cn.senjoeson.triper.R;
import cn.senjoeson.triper.base.MyApplication;
import cn.senjoeson.triper.bean.PlaceBean;

/**
 * Created by senjoeson on 2018/2/10.
 */

public class SearchAdapter extends BaseAdapter implements Filterable {


    private final Context mContext;
    private final List<PlaceBean> mDataLists;
    private MyFilter mMyFilter;

    public SearchAdapter(Context context, List<PlaceBean> mDataLists) {
        this.mContext = context;
        this.mDataLists = mDataLists;
    }


    @Override
    public int getCount() {
        return mDataLists.size();
    }

    @Override
    public PlaceBean getItem(int position) {
        return mDataLists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.dinninglist_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        PlaceBean placeBean = mDataLists.get(position);

        viewHolder.mDinnerName.setText(placeBean.getPlaceName());
        GlideUtils.loadImage(MyApplication.getContext(), placeBean.getImageUrl(), viewHolder.mDinnerImage);

        return convertView;
    }


    @Override
    public Filter getFilter() {
        if (mMyFilter != null) {
            mMyFilter = new MyFilter();
        }
        return mMyFilter;
    }

    /**
     * 筛选结果
     */
    private class MyFilter extends Filter {
        @Override
        protected FilterResults performFiltering(CharSequence charSequence) {
            return null;
        }

        @Override
        protected void publishResults(CharSequence charSequence, FilterResults filterResults) {

        }
    }

    class ViewHolder {
        @BindView(R.id.dinnerImage)
        ImageView mDinnerImage;
        @BindView(R.id.dinnerName)
        TextView mDinnerName;
        @BindView(R.id.ratingbar)
        RatingBar mRatingbar;
        @BindView(R.id.love)
        ImageView mLove;
        @BindView(R.id.add)
        ImageView mAdd;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
